package tetris.agent;
import java.util.ArrayList;

import tetris.features.*;
import tetris.simulator.State;

public class DellacherieAgent extends Agent{
  protected Feature feature;
  double[] weights;
  public DellacherieAgent() {

    ArrayList<Feature> featureSet = new ArrayList<Feature>();
    featureSet.add(new LandingHeightFeature());
    featureSet.add(new ErodedFeature());
    featureSet.add(new RowTransitionFeature());
    featureSet.add(new ColTransitionFeature());
    featureSet.add(new HolesFeature());
    featureSet.add(new CumulativeWellsFeature());
    this.feature = new ConcatenateFeature(featureSet);

    weights = new double[] {-1,1,-1,-1,-4,-1};
  }

  public int chooseAction(State s, int[][] legalMoves) {
    double bestValue = Double.NEGATIVE_INFINITY;
    int bestMove = 0;
    for (int i = 0; i< legalMoves.length; i++) {
      State tetrisState = new State(s);
      tetrisState.makeMove(i);
      ArrayList<Double> featureVector = feature.getFeatureVector(tetrisState);
      double value = 0;
      for (int j = 0; j < featureVector.size(); j++) {
        value += weights[j]*featureVector.get(j).doubleValue();
      }
      if (value > bestValue) {
        bestValue = value;
        bestMove = i;
      }
    }
    return bestMove;
  }

}
